package IU;

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import Implementacao.Estado;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

import java.awt.Font;
import IU.ContageThread;
import java.awt.Component;
import javax.swing.Box;
import javax.swing.JSeparator;
import javax.swing.JTextArea;

@SuppressWarnings("serial")
public class TelaEstagio extends JFrame {

	private JPanel contentPane;
	private ArrayList< Estado > estados = new ArrayList< Estado > ();
	private JPanel panel;
	private Date dateEvent = new Date();  
	private JLabel lblNewLabel;
	@SuppressWarnings("unused")
	private ContageThread contagem;
	private int cY=0;
	@SuppressWarnings("unused")
	private String nomeEstagio;
	@SuppressWarnings("unused")
	private String descricao;
	private JButton botaoSetaCima; 
	private JButton botaoSetaBaixo; 
	private JPanel panelDescricao;
	private JSeparator separator;
	private JSeparator separator_1;
	
	/**
	 * Create the frame.
	 */
	public TelaEstagio(String nomeEstagio, ArrayList <Estado> estados, String descricao){
		this.nomeEstagio=nomeEstagio;
		this.estados=estados;
		this.descricao=descricao;
		inicializarComponentes();
		criarEstados();

		
	}
	
	
	public void inicializarComponentes() {
		setTitle("Montanha de Chomysky -" +nomeEstagio);
		setExtendedState(JFrame.MAXIMIZED_BOTH);  
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		panel = new JPanel();
		panel.setBackground(Color.WHITE);
		panel.setBounds(0, 0, 1362, 705);
		this.getContentPane().add(panel, BorderLayout.CENTER);
		contentPane.add(panel);
		panel.setLayout(null);
	    
	    JPanel panel_1 = new JPanel();
	    panel_1.setBackground(Color.WHITE);
	    panel_1.setBounds(10, 621, 252, 73);
	    panel.add(panel_1);
	    panel_1.setLayout(null);
	    
	    lblNewLabel = new JLabel("Tempo:");
	    lblNewLabel.setBounds(10, 11, 232, 51);
	    lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 32));
	    panel_1.add(lblNewLabel);
	    
	    JPanel panel_2 = new JPanel();
	    panel_2.setBackground(Color.WHITE);
	    panel_2.setBounds(0, 602, 606, 103);
	    panel.add(panel_2);
	    panel_2.setLayout(null);
	    
	    JButton btnNewButton = new JButton("");
	    btnNewButton.addActionListener(new ActionListener() {
	    	public void actionPerformed(ActionEvent arg0) {
	    		dispose();
	    		TelaInicial tela = new TelaInicial();
	    		tela.setVisible(true);
	    	}
	    });
	    btnNewButton.setIcon(new ImageIcon("C:\\Users\\Lucas Sampaio\\Workspace\\MontanhaDeChomsky\\Images\\sair-icon.gif"));
	    btnNewButton.setForeground(Color.WHITE);
	    btnNewButton.setBackground(Color.WHITE);
	    btnNewButton.setBorderPainted(false);
	    btnNewButton.setBounds(282, 17, 89, 75);
	    panel_2.add(btnNewButton);
	    
	    JButton button = new JButton("");
	    button.setIcon(new ImageIcon("C:\\Users\\Lucas Sampaio\\Workspace\\MontanhaDeChomsky\\Images\\ajuda-icon.png"));
	    button.setForeground(Color.WHITE);
	    button.setBackground(Color.WHITE);
	    button.setBorderPainted(false);
	    button.setBounds(381, 17, 89, 75);
	    panel_2.add(button);
	    
	    JButton button_1 = new JButton("");
	    button_1.setIcon(new ImageIcon("C:\\Users\\Lucas Sampaio\\Workspace\\MontanhaDeChomsky\\Images\\submissao-icon.png"));
	    button_1.setForeground(Color.WHITE);
	    button_1.setBackground(Color.WHITE);
	    button_1.setBorderPainted(false);
	    button_1.setBounds(480, 17, 89, 75);
	    panel_2.add(button_1);
	    
	    panelDescricao = new JPanel();
	    panelDescricao.setBackground(Color.WHITE);
	    panelDescricao.setBounds(0, 0, 1362, 167);
	    panel.add(panelDescricao);
	    
	    botaoSetaBaixo = new JButton("");
	    botaoSetaBaixo.setBounds(661, 0, 49, 38);
	    panel.add(botaoSetaBaixo);
	    botaoSetaBaixo.setBorderPainted(false);
	    botaoSetaBaixo.setVisible(false);
	    botaoSetaBaixo.addActionListener(new ActionListener() {
	    	public void actionPerformed(ActionEvent arg0) {
	    		botaoSetaBaixo.setVisible(false);
	    		panelDescricao.setVisible(true);
	    		botaoSetaCima.setVisible(true);
	    	}
	    });
	    botaoSetaBaixo.setForeground(Color.WHITE);
	    botaoSetaBaixo.setBackground(Color.WHITE);
	    botaoSetaBaixo.setIcon(new ImageIcon("C:\\Users\\Lucas Sampaio\\Workspace\\MontanhaDeChomsky\\Images\\baixo-icon.png"));
	    
	    botaoSetaCima = new JButton("");
	    botaoSetaCima.setBounds(664, 124, 46, 41);
	    botaoSetaCima.addActionListener(new ActionListener() {
	    	public void actionPerformed(ActionEvent e) {
	    		botaoSetaCima.setVisible(false);
	    		botaoSetaBaixo.setVisible(true);
	    		panelDescricao.setVisible(false);
	    	}
	    });
	    panelDescricao.setLayout(null);
	    panelDescricao.add(botaoSetaCima);
	    botaoSetaCima.setIcon(new ImageIcon("C:\\Users\\Lucas Sampaio\\Workspace\\MontanhaDeChomsky\\Images\\cima-icon.png"));
	    botaoSetaCima.setForeground(Color.WHITE);
	    botaoSetaCima.setBackground(Color.WHITE);
	    botaoSetaCima.setBorderPainted(false);
	    
	    
	    separator = new JSeparator();
	    separator.setBounds(0, 165, 1376, 2);
	    panelDescricao.add(separator);
	    
	    JTextArea textAreaDescricao = new JTextArea();
	    textAreaDescricao.setEditable(false);
	    textAreaDescricao.setFont(new Font("Tahoma", Font.PLAIN, 18));
	    textAreaDescricao.setBounds(10, 11, 1342, 110);
	    panelDescricao.add(textAreaDescricao);
	    textAreaDescricao.setText(descricao);
	    
	    separator_1 = new JSeparator();
	    separator_1.setBounds(-16, 38, 1380, 7);
	    panel.add(separator_1);
	    
	    panel.repaint();
	    
	    contadorRegressivo();
	   	
		
	}
	
	public void criarEstados(){
		int x = estados.size();
		for (int i=0; i<x; i++){
			desenharEstados(estados.get(i));
	    }
	}
	
	
	public void desenharEstados (Estado estado){	
		
		DesenhosGraficos p = new DesenhosGraficos( estado );
	    estados.add( estado );
	    
	    panel.add( p );
	    if(estado.getEstadoInicial()){
	    	p.setBounds(1200, 600, 95, 70);
	    }else{
	    	p.setBounds(1225, 520-cY, 70, 70);
	    	cY=cY+80;
	    }
	    panel.repaint();
		
	}
	
	@SuppressWarnings("deprecation")
	public void contadorRegressivo (){
		
		Date hoje = new Date();  
		int minutos = hoje.getMinutes()+15;
		int segundos = hoje.getSeconds();
		String tempo = Integer.toString(minutos)+":"+Integer.toString(segundos);
		
		try {
					dateEvent = new SimpleDateFormat("mm:ss").parse(tempo);
					contagem = new ContageThread(lblNewLabel, dateEvent);  
			    	 
		    	 } catch (ParseException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}  
		    	
		     }
}
